package pl.rgolcz.antnet;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Paint;

import javax.swing.JPanel;

import org.apache.commons.collections15.Transformer;

import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;

@SuppressWarnings("serial")
public class Visualize extends JPanel
{
    public Visualize(Graph<Integer, IWeightedEdge> mGraph) {
        setBackground(Color.WHITE);
        // show graph
        final Layout<Integer, IWeightedEdge> layout = new FRLayout<Integer, IWeightedEdge>(mGraph);
        final VisualizationViewer<Integer, IWeightedEdge> vv = new VisualizationViewer<Integer, IWeightedEdge>(layout);
        vv.setBackground(Color.WHITE);
        
        Transformer<IWeightedEdge, String> stringer = new Transformer<IWeightedEdge, String>(){
            public String transform(IWeightedEdge e) {
                return String.format("%5.2f", e.getWeight());
            }
        };
        vv.getRenderContext().setEdgeLabelTransformer(stringer);
        
        vv.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() {
            public String transform(Integer v) {
                return "" + v;
            }
        });
        vv.setGraphMouse(new DefaultModalGraphMouse<String, IWeightedEdge>());
        
        setLayout(new BorderLayout());
        add(vv, BorderLayout.CENTER);
    }
    
    /**
     * @author danyelf
     */
    public class MyVertexDrawPaintFunction<V> implements Transformer<V,Paint> {

        public Paint transform(V v) {
            return Color.black;
        }

    }
}
